﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace SerialportSample
{
    public partial class SerialportSampleForm : Form
    {
        #region 串口
        //初始化串口的一个新实例
        private SerialPort comm = new SerialPort();
        private StringBuilder builder = new StringBuilder();//避免在事件处理方法中反复的创建，定义到外面。

        private long send_count = 0;//发送计数
        private int delayTime = 1000;
        private Thread sendThread = null;
        private String path = "";
        private bool pauseFlag = false;
        private bool sendFlag = false;
        #endregion

        public SerialportSampleForm()//构造函数
        {
            InitializeComponent();
            //初始化下拉串口名称列表框
            //获取当前计算机串口的名称数组
            //this.skinEngine1.SkinFile = "DeepGreen.ssk";//导入皮肤
            /*开启线程*/


        }


        private void SerialportSampleForm_FormClosing(object sender, FormClosingEventArgs e)
        {

            //在关闭窗体前发生，此时可以取消窗体的关闭。
            DialogResult result = MessageBox.Show("你确定非意外关闭吗！", "友情提示",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (result == DialogResult.OK)
            {
                e.Cancel = false;  //点击OK
                if (comm.IsOpen)
                {
                    //串口打开时点击按钮，则关闭串口
                    comm.Close();
                }
                //设置按钮的状态
                buttonOpenClose.Text = comm.IsOpen ? "关闭" : "打开";
                System.Environment.Exit(System.Environment.ExitCode);
                this.Dispose();
                this.Close();
            }
            else
            {
                e.Cancel = true;
            }

        }


        private void button1_Click(object sender, EventArgs e)
        {


        }

        private void 配置信息修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 配置文件查看ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

    }
}